package Vehicle;
/*
 * 需要有可以租赁的汽车
 * 初始化数据
 * 根据用户需求提供相应的车辆
 */
public class VehicleBusiness {
	//初始化方法，数据
	private Vehicle[] vs=new Vehicle[16];
	public void init() {
		vs[0]=new Car("沪A83BT5", "凯迪拉克", 699, "XT4");
		vs[1]=new Car("沪A98CT2", "凯迪拉克", 899, "XT5");
		vs[2]=new Car("沪A87T90", "凯迪拉克", 1099, "XT6");
		vs[3]=new Car("沪H97582", "奔驰", 799, "GLC");
		vs[4]=new Car("沪H33J49", "奔驰", 999, "E206L");
		vs[5]=new Car("沪H27665", "奔驰", 1299, "S350L");
		vs[6]=new Car("沪MH6115", "特斯拉", 599, "Model 3");
		vs[7]=new Car("沪M98L36", "特斯拉", 899, "Model X");
		vs[8]=new Car("沪M48T11", "特斯拉", 1199, "Model S");
		vs[9]=new Car("沪N36982", "玛莎拉蒂", 1299, "Ghibli");
		vs[10]=new Car("沪N7T276", "玛莎拉蒂", 1599, "Levante");
		vs[11]=new Car("沪N76821", "玛莎拉蒂", 1899, "总裁");
		vs[12]=new Bus("沪C68U35", "金龙", 700, 53);
		vs[13]=new Bus("沪G87967", "金龙", 550, 45);
		vs[14]=new Bus("沪P87230", "考斯特", 450, 22);
		vs[15]=new Bus("沪N23Q89", "考斯特", 600,37 );
	}
	
	//根据用户需求提供车辆
	public Vehicle leaseOut(String brand,String model,int seat) {
		//循环遍历数组，vs数组里的元素都是Vehicle
		//用foreach循环
		for(Vehicle v:vs) {
			//判断v属于轿车还是客车
			if(v instanceof Car) {
				//v属于轿车类型，用向下转型，将v强制转换成Car类型
				Car car =(Car)v;
				if(car.getBrand().equals(brand) && car.getModel().equals(model)) {
					return v;
				}
			}else {
				Bus bus = (Bus )v;
				if(bus.getBrand().equals(brand) && bus.getSeatCount()==seat) {
					return v;
				}
			}
		}
		return null;
		
	}
}
